package com.ruoyi.web.controller.construction.strategy;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.system.domain.construction.strategy.ConstructionStrategyDetail;
import com.ruoyi.system.service.construction.strategy.ConstructionStrategyDetailService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 施工攻略详情Controller
 * 
 * @author zhangshaocong
 * @date 2020-12-03
 */
@RestController
@RequestMapping("/construction/detail")
public class ConstructionStrategyDetailController extends BaseController
{
    @Autowired
    private ConstructionStrategyDetailService constructionStrategyDetailService;

    /**
     * 查询施工攻略详情列表
     */
    @PreAuthorize("@ss.hasPermi('construction:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConstructionStrategyDetail constructionStrategyDetail)
    {
        startPage();
        List<ConstructionStrategyDetail> list = constructionStrategyDetailService.selectConstructionStrategyDetailList(constructionStrategyDetail);
        return getDataTable(list);
    }

    /**
     * 导出施工攻略详情列表
     */
    @PreAuthorize("@ss.hasPermi('construction:detail:export')")
    @Log(title = "施工攻略详情", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ConstructionStrategyDetail constructionStrategyDetail)
    {
        List<ConstructionStrategyDetail> list = constructionStrategyDetailService.selectConstructionStrategyDetailList(constructionStrategyDetail);
        ExcelUtil<ConstructionStrategyDetail> util = new ExcelUtil<ConstructionStrategyDetail>(ConstructionStrategyDetail.class);
        return util.exportExcel(list, "detail");
    }

    /**
     * 获取施工攻略详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('construction:detail:query')")
    @GetMapping(value = "/{strategyDetailId}")
    public AjaxResult getInfo(@PathVariable("strategyDetailId") Long strategyDetailId)
    {
        return AjaxResult.success(constructionStrategyDetailService.selectConstructionStrategyDetailById(strategyDetailId));
    }

    /**
     * 新增施工攻略详情
     */
    @PreAuthorize("@ss.hasPermi('construction:detail:add')")
    @Log(title = "施工攻略详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConstructionStrategyDetail constructionStrategyDetail)
    {
        if (UserConstants.NOT_UNIQUE.equals(constructionStrategyDetailService.checkConstructionStrategyDetailById(constructionStrategyDetail.getConstructionStrategyId())))
        {
            return AjaxResult.error("新增施工案例'" + constructionStrategyDetail.getStrategyDetailTitle() + "'失败，施工案例原文只能有一条");
        }
        return toAjax(constructionStrategyDetailService.insertConstructionStrategyDetail(constructionStrategyDetail));
    }

    /**
     * 修改施工攻略详情
     */
    @PreAuthorize("@ss.hasPermi('construction:detail:edit')")
    @Log(title = "施工攻略详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConstructionStrategyDetail constructionStrategyDetail)
    {
        return toAjax(constructionStrategyDetailService.updateConstructionStrategyDetail(constructionStrategyDetail));
    }

    /**
     * 删除施工攻略详情
     */
    @PreAuthorize("@ss.hasPermi('construction:detail:remove')")
    @Log(title = "施工攻略详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{strategyDetailIds}")
    public AjaxResult remove(@PathVariable Long[] strategyDetailIds)
    {
        return toAjax(constructionStrategyDetailService.deleteConstructionStrategyDetailByIds(strategyDetailIds));
    }
}
